package app.myproject;

//file Serve.java  
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class DownloadServlet extends HttpServlet {
	
	private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {

		try {
			String key = req.getParameter("key");
			
			if (key != null) {
				BlobKey blobKey = new BlobKey(key);
				blobstoreService.serve(blobKey, res);
			}
		}
		catch(Exception e) {e.printStackTrace();}

	}
}